/*
package com.healthcloud.rabbitmq.producer;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.healthcloud.rabbitmq.entity.Order;
import com.healthcloud.dao.BrokerMessageLogMapper;
import com.healthcloud.utils.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.Connection;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

*/
/**
 * @Author yucl
 * @date 2018/7/24
 *//*

@Transactional
@Service("producer")
@Slf4j
public class Producer {


    */
/**
     * 自动注入RabbitTemplate模板类
     *//*

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private ConnectionFactory connectionFactory;

    @Autowired
    private BrokerMessageLogMapper brokerMessageLogMapper;

    public void sendMessage(Object message,String exchange,String routingKey,String messageId) {

        Connection connection = connectionFactory.createConnection();
        final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);



        rabbitTemplate.setMandatory(true);
        rabbitTemplate.setExchange(exchange);

        rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());

        */
/**
         * 消息是否达到exchanage
         *//*

        rabbitTemplate.setConfirmCallback(confirmCallback);

        CorrelationData date = new CorrelationData(messageId);

        JSONObject object = JSON.parseObject(message.toString());
        object.put("messageId",messageId);
        rabbitTemplate.convertAndSend(exchange,routingKey,object,date);
    }


    */
/**
     * 发送消息方法调用: 构建自定义对象消息
     * @param order
     * @throws Exception
     *//*

    public void sendMessage(Order order) throws Exception {
        rabbitTemplate.setConfirmCallback(confirmCallback);
        //消息唯一ID
        CorrelationData correlationData = new CorrelationData(order.getMessageId());
        rabbitTemplate.convertAndSend(Constants.SMART_DIRECT, "smart.key.*", order, correlationData);
    }


    */
/**
     * 回调函数: confirm确认
     *//*

    final RabbitTemplate.ConfirmCallback confirmCallback = new RabbitTemplate.ConfirmCallback() {
        @Override
        public void confirm(CorrelationData correlationData, boolean ack, String cause) {
           log.info("correlationData: {}" , correlationData);
            String messageId = correlationData.getId();
            if(ack){
                //如果confirm返回成功 则进行更新
                brokerMessageLogMapper.changeBrokerMessageLogStatus(messageId, Constants.ORDER_SEND_SUCCESS, new Date());
            } else {
                //失败则进行具体的后续操作:重试 或者补偿等手段
                log.error("messageId = " + messageId + "发生异常，异常原因 = " + cause);
            }
        }
    };
}
*/
